import md5 from './md5.js';
import base64 from './base64.js';
import {
	APP_KEY
} from '@/config/index.js';
const PUBLIC_KEY = "DBD4ED90387062F892DF0B4DBC079C42";

const getAppSign = (timestamp) => {
	return base64.encode(md5.hex_md5(PUBLIC_KEY + APP_KEY + timestamp));
};

const mobileFormat = (mobile) => {
	let result = '';
	if (mobile) {
		result = mobile.slice(0, 3) + "****" + mobile.slice(-4);
	}
	return result
}

const timeDiffs = (endDate, startDate) => {
	const etr = endDate.replace(/\-/ig, '/');
	if (startDate) {
		const str = endDate.replace(/\-/ig, '/');
		return ((new Date(etr)).getTime() - (new Date(str)).getTime()) 
	}
	return ((new Date(etr)).getTime() - (new Date()).getTime()) 
}

export {
	getAppSign,
	mobileFormat,
	timeDiffs
}